#ifndef __FORWARD_SESSION_H_INCLUDED__
#define __FORWARD_SESSION_H_INCLUDED__

#include <netinet/in.h>
#include <unistd.h>
#include "forward_buffer.h"
#include "forward_pair.h"
#include "forward_event.h"
#include "timer_domain.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * forward session
 */
class forward_session{

public:

	enum FORWARD_DIRECTION{
		OUTWARD,
		INWARD
	};

    enum FORWARD_STATUS{
		CREATED,
        CONNECTING,
        CONNECTED
    };

	forward_session(forward_pair& fwd_pair);

	virtual ~forward_session();

	inline forward_pair& get_pair(){
		return fwd_pair;
	}

	inline void set_pair(forward_pair& fwd_pair){
		this->fwd_pair = fwd_pair;
	}

	inline forward_event& get_evt_in(){
		return evt_in;
	}

	inline forward_event& get_evt_out(){
		return evt_out;
	}

    virtual void close();

    virtual void reset();

	virtual const char* to_string();

	void auto_release(bool ar);

    // 转发报文，-1失败，0成功
    virtual int packet_forward(FORWARD_DIRECTION direction){};

    // -1=失败 0=没有挂起 1=仍挂起 2=挂起已完成
    virtual int pend_forward(FORWARD_DIRECTION direction){};

    timer_domain td;

private:

	void init();

	forward_pair fwd_pair;

	bool ar;

protected:

	// 转发事件
	forward_event evt_in;
	forward_event evt_out;
};

#ifdef __cplusplus
}
#endif

#endif // __FORWARD_SESSION_H_INCLUDED__
